Repository navigation
feat(plugin-js,plugin-simplicity): add no-mixed-libraries and no-reinvented-helper - #97
Open
luoling8192 wants to merge 2 commits into
Open
luoling8192 wants to merge 2 commits into
luoling8192 wants to merge 2 commits into
Conversation
The rule reports the imports of a library when the workspace also uses another library for the same job, for example zod and valibot. It collects the external package imports of every source file once per run, and asks the model one time to group the packages that do the same job. A group that names a package no file imports, or that an allow set covers, is dropped. A preferred package becomes the canonical member of its group. Diagnostics go only to the linted files. The rule is registered but not in recommended, because it reads the whole workspace. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The rule reports a small helper when a utility library that the repository already depends on exports the same function. The libraries come from the rule options. The rule loads each one from the linted workspace to read its real export names, and drops a finding that names an unknown helper, library, or export. It uses the shared index of small helpers and the settings.simplicity options. The shared helpers now accept a rule context with options, because this is the first simplicity rule that takes options. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds two model-backed rules for dependency hygiene. ESLint
no-restricted-importscan ban a known library, but it cannot find two libraries that do the same job, or a helper that a dependency already exports. A model can.js/no-mixed-librariesreports the imports of a library when the workspace also uses another library for the same job, for examplezodandvalibot.simplicity/no-reinvented-helperreports a small helper when a utility library that the repository already depends on exports the same function, for example a localclampnext toes-toolkit.Both rules started in the moeru-ai/airi monorepo, which uses one library for each job by policy. This PR moves them here in a general form: the AIRI package names and libraries are now options. Neither rule is in a
recommendedpreset.Change map
plugin-jsno-mixed-librariesplugin-simplicityno-duplicated-helper,no-needless-helperno-reinvented-helpersettings.simplicity. One model call per file that has a helperplugin-simplicityshared helpersctx: RuleContextctx: RuleContext<readonly unknown[]>options, so behavior does not changejs/no-mixed-libraries*.{ts,tsx,mts,cts,js,jsx,mjs,cjs,vue}file with@alint-js/tools-fs, and reads the package names with a text scan of static, side-effect, dynamic, andrequireimports. Packages that a workspacepackage.jsonnames,@types/*, and built-in modules are left out.ctx.src, the same key that the simplicity index uses.allowset covers. Apreferredpackage overrides the canonical package that the model chose.cache: false, because the verdict depends on every file in the workspace. It usesonTargetFilerather thanonTargetProject, so it works in a config item that hasfiles.simplicity/no-reinvented-helperlibraries(at least one) from its options.require.resolverejects a package whoseexportsmap has only animportcondition, so the rule then finds the manifest in thenode_modulesdirectories that Node searches.It respects
settings.simplicity.judgeandignores. It uses the core cache with the prompt ascacheKey. A library upgrade that adds an export reaches a cached file only after the file or the options change. The README states this.Boundaries and risks
no-mixed-librariesctx.srcVerification
The rule tests run the real rule against a temporary workspace and answer the model call from a local HTTP server, as the existing
no-needless-helpertests do. Theno-reinvented-helperworkspace has an ESM-only library with animport-onlyexportsmap.Not verified:
no-mixed-librariesreported 47 imports in four AIRI workspaces, and all groups matched a manual audit (for examplezodtovalibot,localforagetounstorage). It missedasync-mutexto thees-toolkitMutex.no-reinvented-helperreported 4 helpers in 8 sample files, all correct (sleepandclamp), with no false positive in 3 control files. The prompts here are the same, but the code changed, so treat these numbers as a hint, not as evidence for this PR.🤖 Generated with Claude Code